using System;
using System.Collections;
using System.Collections.Generic;
using Animancer;
using UnityEngine;

public class HealthProp : MonoBehaviour {
	public int hp;
	public int maxHp;
	public HealthBar healthBar;
	public bool destroyOnDie;
	public UnityEvent OnHit;
	public UnityEvent OnDeath;

	public enum Type {
		Rock,
		Enemy
	}
	public Type type;

	public void DoDamage(int damage)
	{
		hp -= damage;
		if (hp <= 0)
		{
			OnDeath.Invoke();
		}
		else
		{
			OnHit.Invoke();
		}
	}
	public void FixedUpdate() {
		if (maxHp == hp) {
			healthBar.SetShow(false);
			return;
		}
		healthBar.SetShow(true);
		healthBar.SetFill((float)hp / Mathf.Max(1, maxHp));

		if (hp <= 0 && gameObject != null && destroyOnDie) {
			TilemapDataManager.Instance.SetData(transform.position, new CustomTileData());
			Destroy(gameObject);
		}
	}
	
}
